package br.com.logica;

import br.com.dao.ClienteDao;
import br.com.dao.ClienteDaoImpl;
import br.com.excecoes.ClienteException;
import br.com.excecoes.DAOException;
import br.com.modelo.Cliente;
import java.util.List;

/**
 *
 * @author Gernan
 */
public class ClienteBusinessImpl implements ClienteBusiness {

    private ClienteDao clienteDao;

    public ClienteBusinessImpl() {
        clienteDao = new ClienteDaoImpl();
    }

    private void verificarCampos(Cliente cliente) throws ClienteException {
        Boolean contemErros = false;
        String erro = "";
        if (contemErros) {
            throw new ClienteException(erro);
        }
    }

    @Override
    public Cliente salvar(Cliente cliente) throws ClienteException {
        verificarCampos(cliente);
        try {
            return clienteDao.save(cliente);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }

    @Override
    public Cliente atualizar(Cliente banco) throws ClienteException {
        verificarCampos(banco);
        try {
            return clienteDao.update(banco);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }
    
    @Override
    public Cliente remover(Cliente banco) throws ClienteException {
        try {
            return clienteDao.remove(banco);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }

    @Override
    public Cliente getPorId(Long id) throws ClienteException {
        try {
            return clienteDao.getPorId(id);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }

    @Override
    public Cliente getPorCpf(String cpf) throws ClienteException {
        try {
            return clienteDao.getPorCpf(cpf);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }

    @Override
    public List<Cliente> buscar(String busca) throws ClienteException {
        try {
            return clienteDao.buscar(busca);
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }
    
    @Override
    public List<Cliente> getTodos() throws ClienteException {
        try {
            return clienteDao.getTodos();
        } catch (DAOException ex) {
            throw new ClienteException(ex.getMessage());
        }
    }
}
